package com.czk.history;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;

import java.util.List;

/**
 * 历史数据的操作
 * @Author ChenZhangKun
 * @Date 2020/9/10 16:22
 */
public class HistoryQuery {
    public static void main(String[] args) {
        // 得到流程引擎
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 得到历史操作
        HistoryService historyService = processEngine.getHistoryService();
        // 得到查询器
        HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
        // 设置查询条件
        // 设置流程实例的id查询
        historicActivityInstanceQuery.processInstanceId("2501");
        // 执行查询
        List<HistoricActivityInstance> list = historicActivityInstanceQuery.orderByHistoricActivityInstanceStartTime().asc().list();
        // 遍历数据
        list.forEach(x->{
            System.out.println(x.getActivityId());
            System.out.println(x.getActivityName());
            System.out.println(x.getProcessDefinitionId());
            System.out.println(x.getProcessInstanceId());
        });
    }
}
